package com.teach.basic.service.impl;

import com.teach.basic.model.dto.FoodDTO;
import com.teach.basic.service.FoodsService;
import com.teach.basic.model.po.Foods;
import com.teach.basic.dao.FoodsDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * <p>
 *  美食表 服务实现类
 * </p>
 * @version 1.0
 * @author hzz
 * @since 2020-02-18
 */
@Service
public class FoodsServiceImpl extends ServiceImpl<FoodsDao, Foods> implements FoodsService {
    @Autowired
    private FoodsDao foodsDao;
    public List<Foods> getList(Map<String,String[]> reparam){
        Map<String,Object> param=new HashMap<>();
        for (Map.Entry<String,String[]> i : reparam.entrySet()){
            if(i.getKey().equals("type")){
                if(i.getValue()[0].equals("99")){
                    //TO DO
                }else {
                    param.put("category_" + i.getKey(), i.getValue()[0]);
                }
            }else {
                param.put(i.getKey(), i.getValue()[0]);
            }
        }
        return baseMapper.selectByMap(param);
    }
    @Transactional(rollbackFor = Exception.class)
    public String add(FoodDTO foodDTO){
        foodsDao.insertSelective(foodDTO);
        return foodDTO.getId();
    }
}
